<?php

class PublicAction extends BaseAction{
public function login()
{
$adm_session = es_session::get(md5(conf('AUTH_KEY')));
$adm_name = $adm_session['adm_name'];
$adm_id = intval($adm_session['adm_id']);
if($adm_id != 0)
{
$this->redirect(u('Index/index'));
}
else
{
$this->display();
}
}
public function verify()
{
Image::buildImageVerify(4,1);
}
public function do_login()
{
$adm_name = trim($_REQUEST['adm_name']);
$adm_password = trim($_REQUEST['adm_password']);
$ajax = intval($_REQUEST['ajax']);
if($adm_name == '')
{
$this->error(L('ADM_NAME_EMPTY',$ajax));
}
if($adm_password == '')
{
$this->error(L('ADM_PASSWORD_EMPTY',$ajax));
}
if(es_session::get('verify') != md5($_REQUEST['adm_verify'])) {
$this->error(L('ADM_VERIFY_ERROR'),$ajax);
}
$condition['adm_name'] = $adm_name;
$condition['is_effect'] = 1;
$condition['is_delete'] = 0;
$adm_data = M('Admin')->where($condition)->find();
if($adm_data) 
{
if($adm_data['adm_password']!=md5($adm_password))
{
save_log($adm_name.L('ADM_PASSWORD_ERROR'),0);
$this->error(L('ADM_PASSWORD_ERROR'),$ajax);
}
else
{
$adm_session['adm_name'] = $adm_data['adm_name'];
$adm_session['adm_id'] = $adm_data['id'];
es_session::set(md5(conf('AUTH_KEY')),$adm_session);
$adm_data['login_ip'] = get_client_ip();
$adm_data['login_time'] = get_gmtime();
M('Admin')->save($adm_data);
save_log($adm_data['adm_name'].L('LOGIN_SUCCESS'),1);
$this->success(L('LOGIN_SUCCESS'),$ajax);
}
}
else
{
save_log($adm_name.L('ADM_NAME_ERROR'),0);
$this->error(L('ADM_NAME_ERROR'),$ajax);
}
}
public function do_loginout()
{
$adm_session = es_session::get(md5(conf('AUTH_KEY')));
$adm_id = intval($adm_session['adm_id']);
if($adm_id == 0)
{
$this->redirect(u('Public/login'));
}
else
{
es_session::delete(md5(conf('AUTH_KEY')));
$this->assign('jumpUrl',U('Public/login'));
$this->assign('waitSecond',3);
$this->success(L('LOGINOUT_SUCCESS'));
}
}
public function checkSupplierBooking(){
$now_time = get_gmtime();
$e_time = $now_time -300;
$b_time = $e_time -3600;
$list = M('SupplierLocationOrder')->where("status=0 AND create_time between $b_time AND $e_time ")->findAll();
$this->assign('list',$list);
$this->display();
}
}

?>